package com.hadoop.controller;

import com.hadoop.mybatis.service.UserService;
import com.hadoop.mybatis.vo.UserVo;
import com.hadoop.util.address.OptionCityMap;
import com.hadoop.util.address.OptionMap;
import com.hadoop.util.address.OptionTownMap;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

/**
 * <p></p>
 *
 * @author Andy
 * @date 2017/9/21
 */
@RequestMapping(value = "/user")
@Controller
public class UserController extends BaseController{

    @Resource
    private UserService userService;

    @RequestMapping(value = "/register")
    public String register(Model model) {
        model.addAttribute("prov", OptionCityMap.OPT_LIST_PROVINCE);
        model.addAttribute("city", OptionCityMap.OPT_MAP_CITY);
        model.addAttribute("town", OptionTownMap.OPT_MAP_TOWN);
        return "/reg/register";
    }

    @RequestMapping(value = "/register/post")
    public String registPost(UserVo userVo,Model model) throws Exception {
        int count = userService.save(userVo);
        if (count > 0) {
            return "redirect:/";
        }
        model.addAttribute("msg", "注册失败");
        return "/reg/register";
    }

}
